<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link
	href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<!-- 	구글 지도 API 를 통한 구글맵 게시 	- 너비 사이즈를 블로그메인의 슬라이더 너비와 동일하게 수작업 교체.(by 기석) -->
<div id="blogMap"
	<s:if test="shop_blog.blog_map ==0">class='hide'</s:if>>
	<!-- 지도 타이틀 -->
	<table class="table table-striped" style="width: 1100px;">
		<tr>
			<th class="text-left"><a><span
					class="glyphicon glyphicon-screenshot"></span>&nbsp;상점 위치 </a> 
	<!-- 지도API -->
		<tr>
			<th>
				<div id="map_canvas" style="height: 400px; width: 1100px;"></div>
			</th>
		</tr>
	</table>
</div>
<script type="text/javascript">
	var geocoder;
	var map;
	var marker;
	var faddr_lat;
	var faddr_lng;

	function initialize() {
		geocoder = new google.maps.Geocoder();
		var latlng = new google.maps.LatLng(faddr_lat, faddr_lng);
		var myOptions = {
			zoom : 18,
			center : latlng,
			mapTypeId : google.maps.MapTypeId.ROADMAP
		}
		map = new google.maps.Map(document.getElementById("map_canvas"),
				myOptions);
		addMark(faddr_lat, faddr_lng);
	}

	function codeAddress() {
		var address = document.getElementById("address").value;

		geocoder.geocode({
			'address' : address
		}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				addMark(results[0].geometry.location.lat(),
						results[0].geometry.location.lng());

				for ( var i in results) {
					var li = document.createElement('li');
					var a = document.createElement('a');
					a.href = "javascript:addMark(" + marker.position.lat()
							+ ", " + marker.position.lng() + ");";
					a.innerHTML = results[i].formatted_address;

					li.appendChild(a);
					r.appendChild(li);
				}
			} else {

			}
		});
	}

	function addMark(lat, lng) {
		if (typeof marker != 'undefined') {
			marker.setMap(null);
		}

		marker = new google.maps.Marker({
			map : map,
			position : new google.maps.LatLng(lat, lng)
		});
	}

	function geoCode() {
		var faddr = '${shop.address1}' + ' ' + '${shop.address2}';
		var geocoder;
		geocoder = new google.maps.Geocoder();
		geocoder.geocode({
			'address' : faddr
		}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				faddr_lat = results[0].geometry.location.lat(); //위도
				faddr_lng = results[0].geometry.location.lng(); //경도
			} else {
				faddr_lat = "";
				faddr_lng = "";
			}
			/* alert('주소 : ' + faddr + '위도 : ' + faddr_lat + '경도 : ' + faddr_lng); */
			return initialize();
		});

	}
	geoCode();
</script>
</html>
